<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>批量地址</title>
    <style type="text/css">
        body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
        #l-map{height:300px;width:100%;}
        #r-result{width:100%; font-size:14px;line-height:20px;}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=SmHmywutT146wyRzXMhgajrCG5MxIpo0"></script>
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>

</head>
<body>
<div id="app">
    <div id="l-map"></div>
    <div id="r-result">
        <input type="button" value="批量地址解析" onclick="bdGEO()" />
        <div id="result"></div>
    </div>
</div>

</body>
</html>
<script type="text/javascript">

    // 百度地图API功能
    var map = new BMap.Map("l-map");
    map.centerAndZoom(new BMap.Point(117.269945,31.86713), 13);
    map.enableScrollWheelZoom(true);

    /*ip定位*/
    var myCity = new BMap.LocalCity();
    myCity.get(myFun);
    function myFun(result){
        var cityName = result.name;
        map.setCenter(cityName);
        /* alert("当前定位城市:"+cityName);*/
    }


    /*地址批量逆解析*/
    var index = 0;
    var myGeo = new BMap.Geocoder();
    var adds =
        [
        "成都市市政府",
        "成都市天府三街",
        "成都市火车南站",
        "成都市琉璃场 ",
        "成都市春熙路",
        "成都市一品天下地铁站",
        "成都市新都区熊猫大道",
        "成都市火车东站"
    ];

    function geocodeSearch(add){
        /*alert(adds.length)*/
        if(index < adds.length){
            //图标显示时间间隔控制
            setTimeout(window.bdGEO,400);
        }else{
            return false;
        }
        myGeo.getPoint(add, function(point){
            if (point) {
                //显示的内容
                document.getElementById("result").innerHTML +=  index + "、" + add + ":" + point.lng + "," + point.lat + "</br>";
                /*alert(index)*/
                /*alert(point.lng+":"+point.lat)*/
                //定位
                var address = new BMap.Point(point.lng, point.lat);
                addMarker(address,new BMap.Label(index+":"+add,{offset:new BMap.Size(20,-10)}));
            }
        }, "cityName");
    }
    function bdGEO(){
        //地址
        var add = adds[index];
        /*alert(add)*/
        geocodeSearch(add);
        index++;
    }
    // 编写自定义函数,创建标注
    function addMarker(point,label){
        var marker = new BMap.Marker(point);
        map.addOverlay(marker);
        marker.setLabel(label);
    }




</script>